<?php 
class StringCalculator{
	private $string; //1, 2\n3 = 

	function __construct(){
	}
	
	public function add($string){
		//Check ended wrong characters
		if(!preg_match("/(,|;|\n)$/", $string)){
			
			//Split by this characters
			$values = preg_split("/[\n,;]+/",$string);
			$add = 0;
			
			//Add all the values
			foreach($values as $value){
				$add += (int) $value;
			}
			return $add;
		} else {
			return "error";
		}
	}
}
?>